package net.sf.xoperator.ui.txt;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

import org.openbbs.blackboard.filter.KindOfFilter;

import net.sf.xoperator.blackboard.NoPlanBlackBoardControl;
import net.sf.xoperator.store.RdfStoreInfo;
import net.sf.xoperator.ui.StringMessage;

public class ListDatastoresCommand extends Command {

	@Override
	public String getKeyWord() {

		return "list ds";
	}

	@Override
	public List<Object> performInternal(String call, NoPlanBlackBoardControl control, Interactor interactor) {
		Set<Object> stores = control.getConfigurationContext().blackboard()
				.readAll(new KindOfFilter(RdfStoreInfo.class));
		String returnmessage = "";
		// looks stupid, but cannot cast to Set<RdfStoreInfo>
		for (Object infoobj : stores) {
			RdfStoreInfo info = (RdfStoreInfo) infoobj;
         if(!info.isObsolete()){
            returnmessage += info.getName() + " " + info.getEndpointUri()
            + " \n";   
         }
			
		}
		if (returnmessage.isEmpty()) {
			returnmessage = "No datastores are defined";
		}
		return Arrays.asList(new Object[] { new StringMessage(returnmessage) });
	}

	@Override
	public String getHelp() {
		return "List all the available datastore of this agent.";
	}
	

	@Override
	public Pattern getValidationPattern() {

		return Pattern.compile(".*");
	}

}
